package com.own.component.util.excel.util.write.style.css.impl;

import com.own.component.util.excel.util.write.model.Style;
import com.own.component.util.excel.util.write.style.css.ExcelCssAttribute;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;

import java.util.HashMap;
import java.util.Map;

/**
 * TextAlign
 *
 * @author chenxueli
 * @date 2022-06-15 03:14:15
 */
public class TextAlign implements ExcelCssAttribute {

    /**
     * 居中属性
     */
    public static final TextAlign CENTER = new TextAlign(HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
    private static final Map<String, HorizontalAlignment> HORIZONTAL_MAP = new HashMap<>();
    private static final Map<String, VerticalAlignment> VERTICAL_MAP = new HashMap<>();

    static {
        HORIZONTAL_MAP.put("general", HorizontalAlignment.GENERAL);
        HORIZONTAL_MAP.put("left", HorizontalAlignment.LEFT);
        HORIZONTAL_MAP.put("center", HorizontalAlignment.CENTER);
        HORIZONTAL_MAP.put("right", HorizontalAlignment.RIGHT);
        HORIZONTAL_MAP.put("fill", HorizontalAlignment.FILL);
        HORIZONTAL_MAP.put("justify", HorizontalAlignment.JUSTIFY);
        HORIZONTAL_MAP.put("center_selection", HorizontalAlignment.CENTER_SELECTION);
        HORIZONTAL_MAP.put("distributed", HorizontalAlignment.DISTRIBUTED);

        VERTICAL_MAP.put("top", VerticalAlignment.TOP);
        VERTICAL_MAP.put("center", VerticalAlignment.CENTER);
        VERTICAL_MAP.put("bottom", VerticalAlignment.BOTTOM);
        VERTICAL_MAP.put("justify", VerticalAlignment.JUSTIFY);
        VERTICAL_MAP.put("distributed", VerticalAlignment.DISTRIBUTED);
    }

    private final HorizontalAlignment horizontal;

    private final VerticalAlignment vertical;

    public TextAlign(HorizontalAlignment horizontal) {
        this.horizontal = horizontal;
        this.vertical = null;
    }

    public TextAlign(Horizontal horizontal) {
        this.horizontal = horizontal.getAlignment();
        this.vertical = null;
    }

    public TextAlign(String horizontal) {
        this.horizontal = HORIZONTAL_MAP.get(horizontal);
        this.vertical = null;
    }

    public TextAlign(HorizontalAlignment horizontal, VerticalAlignment vertical) {
        this.horizontal = horizontal;
        this.vertical = vertical;
    }

    public TextAlign(Horizontal horizontal, Vertical vertical) {
        this.horizontal = horizontal.getAlignment();
        this.vertical = vertical.getAlignment();
    }

    public TextAlign(String horizontal, String vertical) {
        this.horizontal = HORIZONTAL_MAP.get(horizontal);
        this.vertical = VERTICAL_MAP.get(vertical);
    }

    /**
     * 渲染成style
     *
     * @param style 样式信息
     */
    @Override
    public void build(Style style) {
        if (horizontal != null) {
//            style.setAlignment(horizontal);
        }
        if (vertical != null) {
//            style.setVerticalAlignment(vertical);
        }
    }

    @Getter
    @AllArgsConstructor
    @SuppressWarnings("all")
    public static enum Horizontal {
        GENERAL(HorizontalAlignment.GENERAL),
        LEFT(HorizontalAlignment.LEFT),
        CENTER(HorizontalAlignment.CENTER),
        RIGHT(HorizontalAlignment.RIGHT),
        FILL(HorizontalAlignment.FILL),
        JUSTIFY(HorizontalAlignment.JUSTIFY),
        CENTER_SELECTION(HorizontalAlignment.CENTER_SELECTION),
        DISTRIBUTED(HorizontalAlignment.DISTRIBUTED);

        private final HorizontalAlignment alignment;

    }

    @Getter
    @AllArgsConstructor
    @SuppressWarnings("all")
    public static enum Vertical {
        TOP(VerticalAlignment.TOP),
        CENTER(VerticalAlignment.CENTER),
        BOTTOM(VerticalAlignment.BOTTOM),
        JUSTIFY(VerticalAlignment.JUSTIFY),
        DISTRIBUTED(VerticalAlignment.DISTRIBUTED);

        private final VerticalAlignment alignment;

    }


}
